﻿using Newtonsoft.Json.Linq;
using System;
using System.Windows.Forms;
using utils;

namespace view
{
    public partial class LoginPage : UserControl
    {

        public Main main;

        public LoginPage(Main main)
        {
            this.main = main;
            InitializeComponent();
        }

        private void Label1_Click(object sender, EventArgs e)
        {

        }

        private void LoginPage_Load(object sender, EventArgs e)
        {

        }

        private void Button1_Click(object sender, EventArgs e)
        {
            string license = this.textBox1.Text;
            string dbcId = this.textBox2.Text;

            if (String.IsNullOrEmpty(license))
            {
                MessageBox.Show("请输入你的license");
                return;
            }

            if (String.IsNullOrEmpty(dbcId))
            {
                MessageBox.Show("请输入你的DBCID");
                return;
            }


            String retString = HttpUtils.Login(license, dbcId);
            if (retString == null)
            {
                MessageBox.Show("登录错误，系统异常!");
                return;
            }


            JObject jo = JObject.Parse(retString);
            if (jo["code"] != null && jo["code"].ToString() == "500")
            {
                MessageBox.Show("错误的注册码");
                return;
            };

            this.main.showPrintConfig(license);
        }

        private void TextBox1_TextChanged(object sender, EventArgs e)
        {

        }
    }
}
